import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-11-01
 * Time:14:11
 */
public class Mystack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_CAPACITY =10;

    public Mystack() {
        this.elem =new int[DEFAULT_CAPACITY];
    }
    public void push(int val){
        if(isFull()){
            this.elem= Arrays.copyOf(this.elem,2*this.elem.length);
        }
        elem[usedSize]=val;
        usedSize++;
    }

    public boolean isFull(){
        if(this.usedSize==this.elem.length){
            return true;
        }
        return false;
    }
    public int pop(){
        if(isEmpty()){
            throw new EmptyException();
        }
        int oldVal= elem[usedSize-1];
        this.usedSize--;
        return oldVal;
    }
    public boolean isEmpty(){
        if(usedSize==0){
            return true;
        }
        return false;
    }
    public int peek(){
        if (isEmpty()) {
            throw new EmptyException();
        }
        return elem[usedSize-1];
    }

}
